import request from '@/utils/request';
import Qs from 'qs';

export function getLogsLevel() {
  return request({
    url: '/api/logs/level',
    method: 'get',
  });
}

export function modifyLogsLevel(data) {
  return request({
    url: '/api/logs/level',
    method: 'put',
    data,
  });
}

export function getServerLog(data) {
  return request({
    url: '/api/logs/server',
    method: 'get',
    params: data,
    paramsSerializer: (params) => {
      return Qs.stringify(params, { arrayFormat: 'repeat' });
    },
  });
}

export function getLogFiles() {
  return request({
    url: '/api/logs/files',
    method: 'get',
  });
}

export function downloadFile(data) {
  return request({
    url: '/api/logs/files/download',
    method: 'get',
    responseType: 'blob',
    params: data,
    paramsSerializer: (params) => {
      return Qs.stringify(params, { arrayFormat: 'repeat' });
    },
  });
}
// 下载全部文件
export function downloadAllFile() {
  return request({
    url: '/api/logs/files/download-all-logs',
    method: 'get',
    responseType: 'blob',
  });
}

export function getClientLog(data) {
  return request({
    url: '/api/logs/web',
    method: 'get',
    params: data,
    paramsSerializer: (params) => {
      return Qs.stringify(params, { arrayFormat: 'repeat' });
    },
  });
}

export function removeClientLog(data) {
  return request({
    url: '/api/logs/web',
    method: 'delete',
    params: data,
    paramsSerializer: (params) => {
      return Qs.stringify(params, { arrayFormat: 'repeat' });
    },
  });
}

export function downloadClientLog(data) {
  return request({
    url: '/api/logs/web/download',
    method: 'get',
    responseType: 'blob',
    params: data,
    paramsSerializer: (params) => {
      return Qs.stringify(params, { arrayFormat: 'repeat' });
    },
  });
}
// 获取定时任务列表
export function getTimingTasks(data) {
  return request({
    url: '/api/schedule-tasks',
    method: 'get',
    params: data,
  });
}
// 获取定时任务的配置
export function getTimingTasksConfigure(id) {
  return request({
    url: `/api/schedule-tasks/${id}`,
    method: 'get',
  });
}
// 更新定时任务配置
export function updateTimingTaskConfigure(data, id) {
  return request({
    url: `/api/schedule-tasks/${id}`,
    method: 'patch',
    data,
  });
}
// 启动定时任务
export function startTimingTask(id) {
  return request({
    url: `/api/schedule-tasks/${id}/start`,
    method: 'patch',
  });
}
// 暂停定时任务
export function pauseTimingTask(id) {
  return request({
    url: `/api/schedule-tasks/${id}/pause`,
    method: 'patch',
  });
}

export default {
  downloadFile,
  getClientLog,
  removeClientLog,
  downloadClientLog,
  getTimingTasks,
  getTimingTasksConfigure,
  updateTimingTaskConfigure,
  startTimingTask,
  pauseTimingTask,
};
